<?php

namespace App\Admin\Controllers;

use App\VideoChannel;
use App\VideoChannelCategory;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
class VideoChannelController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '视频频道';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new VideoChannel());

        $grid->column('id', __('ID'))->sortable();
        $grid->column('name', __('频道名称'));
        $grid->column('desc', __('频道描述'));
        $grid->column('type', __('频道类型'));
        $grid->column('pic_url', __('频道封面图片'))->image();
        $grid->column('videoChannelCategory.name', __('频道分类名称'));
        $grid->column('created_at', __('Created at'));
        $grid->column('updated_at', __('Updated at'));

        $grid->filter(function($filter){
            $filter->equal('type','频道类型');
        });

        return $grid;
    }
    /**
     * Make a show builder.
     *
     * @param mixed   $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(VideoChannel::findOrFail($id));

        $show->field('id', __('ID'));
        $show->field('name', __('频道名称'));
        $show->field('desc', __('频道描述'));
        $show->field('type', __('频道类型'));
        $show->field('pic_url', __('视频频道图片'))->image();
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));


        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new VideoChannel());

        $video_channel_categorys = VideoChannelCategory::all();

        $category_id_options = array();
        foreach ($video_channel_categorys as $item) {
            $category_id_options[$item->id] = $item->name;
        }

        $form->display('id', __('ID'));
        $form->text('name', __('频道名称'));
        $form->text('desc', __('频道描述'));
        $form->text('type', __('频道类型'));
        $form->image('pic_url', __('视频频道图片'));
        $form->select('video_channel_category_id', '频道分类')->options($category_id_options);
        $form->display('created_at', __('Created At'));
        $form->display('updated_at', __('Updated At'));

        return $form;
    }
}
